import {layer} from 'nuijs';
import './style/isLine.less';
import {request} from 'nuijs';
export  function isLine(e,elem,data) {
    e.stopPropagation();
    var me=elem;
    var apiId=me.attr('data-id');
    //var result= 2 ; //result，上线设置为0，下线设置为2
    var that = this ;
    this.self.request('post','api/isHasAuth.do',function(res){
        //判断是否有权限 fail无权限反之有权限 
        if(res.result=='fail'){
            me.closest('tr').find('.m-hint').removeClass('f-dn');
            setTimeout(function(){
                me.closest('tr').find('.m-hint').addClass('f-dn');
            },3000);
        }else{
            me.closest('tr').find('.m-hint').addClass('f-dn');
            layer({
                content:'<p class="m-hint f-tac">确认下线该API接口吗？</p><p class="f-tac m-state">下线后开发者不能正常调用，请提前做好通知</p>',
                width:'400',
                height:'200',
                skin:'down',
                close:{
                    enable:true
                },
                title:'提示',
                cancel:{
                    enable:true,
                    text:'点错了'
                },
                confirm:{
                    enable:true,
                    callback:function(main,index){
                        this.self.hide(index);
                        request.post('api/updateState.do',{'apiId':apiId,'result':2},function(res){
                            if(res.result=='success'){
                                layer({
                                    content:'<p class="e-mt30"><i class="iconfont">&#xe717;</i></p><p class="e-mt10 e-mb30">下线成功</p>',
                                    width:'160',
                                    height:'120',
                                    skin:'line',
                                    title:false,
                                    close:false,
                                    cancel:false
                                });
                                setTimeout(function(){
                                    layer.hide();
                                    that.grid.paging.query('reload');//刷新页面
                                },1000);
                            }
                        });
                    }
                }
            });
        }
    });
    
}
